package com.qingsong.controller;

import com.mybatisflex.core.paginate.Page;
import com.qingsong.dto.ArticleInsertDTO;
import com.qingsong.dto.ArticlePageDTO;
import com.qingsong.dto.ArticleUpdateDTO;
import com.qingsong.entity.Article;
import com.qingsong.vo.ArticleSimpleListVO;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.beans.factory.annotation.Autowired;
import com.qingsong.service.ArticleService;

import java.util.List;

/**
 * 新闻表 控制层。
 *
 * @author qingsong
 * @since 2024-12-22
 */
@Tag(name = "新闻")
@RestController
@RequestMapping("/article")
public class ArticleController {

    @Autowired
    private ArticleService articleService;

    @Operation(summary = "新增-单条", description = "新增一条新闻记录")
    @PostMapping("insert")
    public boolean insert(@Validated @RequestBody ArticleInsertDTO dto) {
        return articleService.insert(dto);
    }

    @Operation(summary = "查询-前N条记录", description = "查询前N条记录")
    @GetMapping("top/{n}")
    public List<Article> top(@PathVariable("n") Long n) {
        return articleService.top(n);
    }

    @Operation(summary = "查询-单条", description = "按主键查询一条新闻记录")
    @GetMapping("select/{id}")
    public Article select(@PathVariable("id") Long id) {
        return articleService.select(id);
    }
    @Operation(summary = "查询-分页", description = "分页查询新闻记录")
    @GetMapping("page")
    public Page<Article> page(@Validated ArticlePageDTO dto) {
        return articleService.page(dto);
    }

    @Operation(summary = "查询-全部", description = "查询全部新闻记录")
    @GetMapping("list")
    public List<Article> list() {
        return articleService.list();
    }

    @Operation(summary = "查询-简单列表", description = "查询简单列表")
    @GetMapping("simpleList")
    public List<ArticleSimpleListVO> simpleList() {
        return articleService.simpleList();
    }


    @Operation(summary = "修改-单条", description = "按主键修改一条新闻记录")
    @PutMapping("update")
    public boolean update(@RequestBody ArticleUpdateDTO dto) {
        return articleService.update(dto);
    }

    @Operation(summary = "删除-单条", description = "按主键删除一条新闻记录")
    @DeleteMapping("delete/{id}")
    public boolean delete(@PathVariable("id") Long id) {
        return articleService.delete(id);
    }

    @Operation(summary = "删除-批量", description = "按主键批量删除新闻记录")
    @DeleteMapping("deleteBatch")
    public boolean deleteBatch(@RequestParam("ids") List<Long> ids) {
        return articleService.deleteBatch(ids);
    }



}